package cn.yuanqiao.web.controller.archive.management;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import cn.yuanqiao.archive.management.domain.YqZtlx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import cn.yuanqiao.archive.management.domain.YqZt;
import cn.yuanqiao.archive.management.service.IYqZtService;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.page.TableDataInfo;

/**
 * 载体Controller
 * 
 * @author sy
 * @date 2023-07-10
 */
@RestController
@RequestMapping("/archive/yqZt")
public class YqZtController extends BaseController
{
    @Autowired
    private IYqZtService yqZtService;

    /**
     * 查询载体列表
     */
    @PreAuthorize("@ss.hasPermi('archive:yqZt:list')")
    @GetMapping("/list")
    public TableDataInfo list(YqZt yqZt)
    {
        startPage();
        List<YqZt> list = yqZtService.selectYqZtList(yqZt);
        return getDataTable(list);
    }

    /**
     * 查询所有载体
     */
//    @PreAuthorize("@ss.hasPermi('archive:yqZt:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll()
    {
        YqZt yqZt = new YqZt();
        return success(yqZtService.selectYqZtListAll(yqZt));
    }

    /**
     * 导出载体列表
     */
    @PreAuthorize("@ss.hasPermi('archive:yqZt:export')")
    @Log(title = "载体", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YqZt yqZt)
    {
        List<YqZt> list = yqZtService.selectYqZtList(yqZt);
        ExcelUtil<YqZt> util = new ExcelUtil<YqZt>(YqZt.class);
        util.exportExcel(response, list, "载体数据");
    }

    /**
     * 获取载体详细信息
     */
    @PreAuthorize("@ss.hasPermi('archive:yqZt:query')")
    @GetMapping(value = "/{ztId}")
    public AjaxResult getInfo(@PathVariable("ztId") Long ztId)
    {
        return success(yqZtService.selectYqZtByZtId(ztId));
    }

    /**
     * 获取载体下载记录
     */
    @PreAuthorize("@ss.hasPermi('archive:yqZt:query')")
    @GetMapping(value = "/getDownloadRecord/{ztId}")
    public AjaxResult getDownloadRecord(@PathVariable("ztId") Long ztId)
    {
        return success(yqZtService.getDownloadRecord(ztId));
    }

    /**
     * 查看载体是否挂载、剩余容量
     */
    @PreAuthorize("@ss.hasPermi('archive:yqZt:query')")
    @GetMapping(value = "/confirm/{ztId}")
    public AjaxResult confirm(@PathVariable("ztId") Long ztId)
    {
        return success(yqZtService.confirm(ztId));
    }

    /**
     * 新增载体
     */
    @PreAuthorize("@ss.hasPermi('archive:yqZt:add')")
    @Log(title = "载体", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YqZt yqZt)
    {
        return success(yqZtService.insertYqZt(yqZt));
    }

    /**
     * 修改载体
     */
    @PreAuthorize("@ss.hasPermi('archive:yqZt:edit')")
    @Log(title = "载体", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YqZt yqZt)
    {
        return success(yqZtService.updateYqZt(yqZt));
    }

    /**
     * 删除载体
     */
    @PreAuthorize("@ss.hasPermi('archive:yqZt:remove')")
    @Log(title = "载体", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ztIds}")
    public AjaxResult remove(@PathVariable Long[] ztIds)
    {
        return success(yqZtService.deleteYqZtByZtIds(ztIds));
    }
}
